<template>
    <div class="qingwu">
        <div class="admin_table_page_title">出售列表</div>
        <div class="unline underm"></div>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false"
                     :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">
                <span slot="action" slot-scope="rows">
                    <a-button icon="file-search" @click="$router.push('/Estate/house/sell/form/'+rows.id)">查看详情</a-button>
                </span>

                <span slot="status" slot-scope="rows">
                    <a-switch v-if="rows.hot == 1" checked-children="hot" @change="onChangeStatus(rows.id)" default-checked/>
                    <a-switch v-else checked-children="hot" @change="onChangeStatus(rows.id)"/>
                </span>

                <span slot="type" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div>{{rows.room}}室{{rows.toilet}}厅{{rows.hall}}卫</div>
                    </div>
                </span>
            </a-table>
            <div class="admin_pagination" v-if="pages>0">
                <a-pagination v-model="params.page" :page-size.sync="params.limit" :total="pages" @change="onChange" show-less-items/>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        components: {},
        props: {},
        data() {
            return {
                params: {
                    page: 1,
                    limit: 20,
                },
                pages: 0, //总页数
                selectedRowKeys: [], // 被选择的行
                columns: [
                    {title: '#', dataIndex: 'id', fixed: 'left'},
                    {title: '用户ID', dataIndex: 'user_id'},
                    {title: '标题', dataIndex: 'title'},
                    {title: '户型', scopedSlots: {customRender: 'type'}},
                    {title: '推荐', scopedSlots: {customRender: 'status'}},
                    {title: '全款', dataIndex: 'money'},
                    {title: '类型', dataIndex: 'house_type'},
                    {title: '发布时间', dataIndex: 'created_at'},
                    {title: '操作', key: 'id', fixed: 'right', scopedSlots: {customRender: 'action'}},
                ],
                list: [],
                type_lists: [{id: 1, title: '整租'}, {id: 2, title: '合租'}]
            };
        },
        watch: {},
        computed: {},
        methods: {
            // 选择框被点击
            onSelectChange(selectedRowKeys) {
                this.selectedRowKeys = selectedRowKeys;
            },
            // 选择分页
            onChange(e) {
                this.params.page = e;
                this.onload();
            },
            onload() {
                this.$get(this.$api.estateHouseSell, this.params).then(res => {
                    this.pages = res.data.pages;
                    this.list = res.data.data;
                });
            },
            onChangeStatus(id) {
                this.$post(this.$api.estateEditHouseSellState, {id: id}).then(res => {
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                    } else {
                        return this.$message.error(res.msg)
                    }
                })
            }
        },
        created() {
            this.onload();
        },
        mounted() {
        }
    };
</script>
<style lang="scss" scoped>

</style>
